package com.listeners;

import com.utils.ExcutorsUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.concurrent.Executors;

@WebListener
public class ApplicaitonContextListener implements ServletContextListener {

    //程序启动完成

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //程序启动的时候创建一个长度为 10 的线程池
        System.err.println("创建线程池了");
        ExcutorsUtils.setExecutorService(Executors.newScheduledThreadPool(10));

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.err.println("销毁线程池了");
        ExcutorsUtils.shutDown();

    }
}
